package com.ly.web.controller.erp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.BankEntity;
import com.ly.heart.service.IBankInfoService;
import com.ly.common.utils.poi.ExcelUtil;
import com.ly.common.core.page.TableDataInfo;

/**
 * 客户/供应商银行账号信息Controller
 *
 * @author cxl
 * @date 2024-05-14
 */
@Api(value = "Bank", tags = "客户/供应商银行账号信息")
@RestController
@RequestMapping("/heart/Bank")
public class BankInfoController extends BaseController
{
    @Autowired
    private IBankInfoService bankEntityService;

    /**
     * 查询客户/供应商银行账号信息列表
     */
    @PreAuthorize("@ss.hasPermi('heart:Bank:list')")
    @GetMapping("/list")
    @ApiOperation("查询客户/供应商银行账号信息列表")
    public TableDataInfo list(BankEntity bankEntity)
    {
        startPage();
        List<BankEntity> list = bankEntityService.selectBankEntityList(bankEntity);
        return getDataTable(list);
    }

    /**
     * 导出客户/供应商银行账号信息列表
     */
    @PreAuthorize("@ss.hasPermi('heart:Bank:export')")
    @Log(title = "客户/供应商银行账号信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出客户/供应商银行账号信息列表")
    public void export(HttpServletResponse response, BankEntity bankEntity)
    {
        List<BankEntity> list = bankEntityService.selectBankEntityList(bankEntity);
        ExcelUtil<BankEntity> util = new ExcelUtil<BankEntity>(BankEntity.class);
        util.exportExcel( list, "客户/供应商银行账号信息数据");
    }

    /**
     * 获取客户/供应商银行账号信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('heart:Bank:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取客户/供应商银行账号信息详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(bankEntityService.selectBankEntityById(id));
    }

    /**
     * 新增客户/供应商银行账号信息
     */
    @PreAuthorize("@ss.hasPermi('heart:Bank:add')")
    @Log(title = "客户/供应商银行账号信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增客户/供应商银行账号信息")
    public AjaxResult add(@RequestBody BankEntity bankEntity)
    {
        return toAjax(bankEntityService.insertBankEntity(bankEntity));
    }

    /**
     * 修改客户/供应商银行账号信息
     */
    @PreAuthorize("@ss.hasPermi('heart:Bank:edit')")
    @Log(title = "客户/供应商银行账号信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改客户/供应商银行账号信息")
    public AjaxResult edit(@RequestBody BankEntity bankEntity)
    {
        return toAjax(bankEntityService.updateBankEntity(bankEntity));
    }

    /**
     * 删除客户/供应商银行账号信息
     */
    @PreAuthorize("@ss.hasPermi('heart:Bank:remove')")
    @Log(title = "客户/供应商银行账号信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除客户/供应商银行账号信息")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bankEntityService.deleteBankEntityByIds(ids));
    }
    @PostMapping("/getNoRepeatBank")
    @ApiOperation("根据税号判重接口")
    public AjaxResult getNoRepeatBank(@RequestBody BankEntity bankEntity)
    {
        BankEntity one = bankEntityService.getOne(new LambdaQueryWrapper<BankEntity>().eq(BankEntity::getTaxId, bankEntity.getTaxId()));
        if (ObjectUtil.isNotEmpty(one)){
            return AjaxResult.error("该税号已存在");
        }
        return AjaxResult.success();
    }


}
